* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 			Economic Policy Uncertainty and Presidential Approval:            *
* 						Evidence from Latin America                           * 
*																			  *
* 					Authors: Myriam Gómez-Méndez & Erwin Hansen                              * 
*                                 (2021)                                      *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*                             Contents                                        *
*       Figure 1 ................................................... 29       *
*       Figure 2 ................................................... 46       *
*       Figure 3 ................................................... 84       *
*                                                                             *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

clear all
set more 1
 
* Set custom directory
global path "C:\Users\Erwin Hansen\Dropbox\01 research\jackie\draft\submission\plos one\R&R\sent\datacode"
cd "${path}"
* Load data
use "figures_data.dta", clear
* Set graph style
grstyle init
grstyle set plain
* Install package to use
net install grc1leg, from(http://www.stata.com/users/vwiggins)

*******************************************************************************
***** Figure 1: The EPU index and Presidential Approval Ratings over time *****
*******************************************************************************
* Generate moving average EPU Index to avoid montyly variability in graph
gen epu_ma = (epu+l.epu+e+l2.epu+l3.epu+l4.epu+l5.epu+l6.epu)/6
* Graph each variable:
set graph off
twoway (line approval Date, lc(navy) lp(dash) lw(medthick)) (line epu_ma Date, yaxis(2) lc(red)) if Country == "Brazil" & epu != . & approval != ., name(brazil, replace) title("Brazil") ytitle("Pres. Approval", axis(1)) ytitle("EPU Index", axis(2)) ylabel(, angle(0) axis(1)) ylabel(, angle(0) axis(2)) xlabel(, angle(30)) xtitle("") legend(label(1 "Pres. Approval") label(2 "EPU Index"))
twoway (line approval Date, lc(navy) lp(dash) lw(medthick)) (line epu_ma Date, yaxis(2) lc(red)) if Country == "Chile" & epu != . & approval != ., name(chile, replace) title("Chile") ytitle("Pres. Approval", axis(1)) ytitle("EPU Index", axis(2)) ylabel(, angle(0) axis(1)) ylabel(, angle(0) axis(2)) xlabel(, angle(30)) xtitle("") legend(label(1 "Pres. Approval") label(2 "EPU Index"))
twoway (line approval Date, lc(navy) lp(dash) lw(medthick)) (line epu_ma Date, yaxis(2) lc(red)) if Country == "Colombia" & epu != . & approval != ., name(colombia, replace) title("Colombia") ytitle("Pres. Approval", axis(1)) ytitle("EPU Index", axis(2)) ylabel(, angle(0) axis(1)) ylabel(, angle(0) axis(2)) xlabel(, angle(30)) xtitle("") legend(label(1 "Pres. Approval") label(2 "EPU Index"))
twoway (line approval Date, lc(navy) lp(dash) lw(medthick)) (line epu_ma Date, yaxis(2) lc(red)) if Country == "Mexico" & epu != . & approval != ., name(mexico, replace) title("Mexico") ytitle("Pres. Approval", axis(1)) ytitle("EPU Index", axis(2)) ylabel(0(20)100, angle(0) axis(1)) ylabel(, angle(0) axis(1)) ylabel(, angle(0) axis(2)) xlabel(, angle(30)) xtitle("") legend(label(1 "Pres. Approval") label(2 "EPU Index"))
set graph on
* Combine and export graph
grc1leg brazil chile colombia mexico, legendfrom(brazil)
graph export fig1.png, as(png) replace


*******************************************************************************
****************** Figure 2: IRF of a shock on the EPU index ******************
*******************************************************************************
* Estimate the PVAR model
pvar epu inflation unemployment ind_production approval
* Get each IRF and use data to graph
set graph off
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(epu inflation unemployment ind_production approval) mc(200) oirf impulse(epu) response(approval) title("Response of Pres. Approval") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf1, replace) save("irf1", replace) yline(0) level(90)
preserve
use "irf1", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(-3(1)1) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of Pres. Approval") name(gr_irf1, replace) yline(0, lc(red))
restore
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(epu inflation unemployment ind_production approval) mc(200) oirf impulse(epu) response(ind_production) title("Response of Industrial Production") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf2, replace) save("irf2", replace) level(90)
preserve
use "irf2", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(-1(.5).5) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of Industrial Production") name(gr_irf2, replace) yline(0, lc(red))
restore
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(epu inflation unemployment ind_production approval) mc(200) oirf impulse(epu) response(inflation) title("Response of Inflation") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf3, replace) save("irf3", replace) level(90)
preserve
use "irf3", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(-.1(.1).3) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of Inflation") name(gr_irf3, replace) yline(0, lc(red))
restore
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(epu inflation unemployment ind_production approval) mc(200) oirf impulse(epu) response(unemployment) title("Response of Unemployment") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf4, replace) save("irf4", replace) level(90)
preserve
use "irf4", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(-.2(.2).4) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of Unemployment") name(gr_irf4, replace) yline(0, lc(red))
restore
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(epu inflation unemployment ind_production approval) mc(200) oirf impulse(epu) response(epu) title("Response of EPU") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf5, replace) save("irf5", replace) level(90)
preserve
use "irf5", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(0(20)60) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of EPU") name(gr_irf5, replace) yline(0, lc(red))
restore
set graph on
* Combine and export graph
grc1leg gr_irf1 gr_irf2 gr_irf3 gr_irf4 gr_irf5, legendfrom(gr_irf1)
graph export fig2.png, as(png) replace


*******************************************************************************
****************** Figure 3: IRF of a shock on the EPU index ******************
*******************************************************************************
* Repeat the procedure considering EPU as the most endogenous variable
pvar epu inflation unemployment ind_production approval
set graph off
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(inflation unemployment ind_production approval epu) mc(200) oirf impulse(epu) response(approval) title("Response of Pres. Approval") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf1, replace) save("irf1", replace) yline(0) level(90)
preserve
use "irf1", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(-3(1)1) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of Pres. Approval") name(gr_irf1, replace) yline(0, lc(red))
restore
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(inflation unemployment ind_production approval epu) mc(200) oirf impulse(epu) response(ind_production) title("Response of Industrial Production") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf2, replace) save("irf2", replace) level(90)
preserve
use "irf2", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(-1(.5).5) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of Industrial Production") name(gr_irf2, replace) yline(0, lc(red))
restore
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(inflation unemployment ind_production approval epu) mc(200) oirf impulse(epu) response(inflation) title("Response of Inflation") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf3, replace) save("irf3", replace) level(90)
preserve
use "irf3", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(-.1(.1).3) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of Inflation") name(gr_irf3, replace) yline(0, lc(red))
restore
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(inflation unemployment ind_production approval epu) mc(200) oirf impulse(epu) response(unemployment) title("Response of Unemployment") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf4, replace) save("irf4", replace) level(90)
preserve
use "irf4", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(-.2(.2).4) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of Unemployment") name(gr_irf4, replace) yline(0, lc(red))
restore
pvarirf, xscale(range(0 12)) xtick(0(3)12) xlabel(0(3)12) step(12) porder(inflation unemployment ind_production approval epu) mc(200) oirf impulse(epu) response(epu) title("Response of EPU") subtitle("") xtitle("") byoption(legend(off) note("")) name(irf5, replace) save("irf5", replace) level(90)
preserve
use "irf5", clear
tw (line irf _step, lc(black) lp(thick)) (line ll _step, lc(black) lp(dash)) (line ul _step, lc(black) lp(dash)), xlabel(0(3)12) ylabel(0(20)60) legend(order(1 "Orthogonalized IRF" 2 "90% CI")) xtitle("") subtitle("Response of EPU") name(gr_irf5, replace) yline(0, lc(red))
restore
set graph on
* Combine and export graph
grc1leg gr_irf1 gr_irf2 gr_irf3 gr_irf4 gr_irf5, legendfrom(gr_irf1)
graph export "fig3.png", as(png) replace
